var utils = require("../../utils/utils");
var time = require("../../utils/time");
var ocrGml = require("../../utils/ocrGml");
var ACTION = require("../../base/action");
var common = require("./common");
var aBless = new ACTION("开福袋");
var inTask = require("./inTask");
aBless.goStart = function () {
  if (common.inHome()) {
    sleep(utils.getRandom(1.5, 2, 1000));
    utils.clickPointMap(common.pointMap["首页我的"]);
    sleep(utils.getRandom(2, 4, 1000));
    utils.clickTextStartsWith("邀请好友");
    sleep(utils.getRandom(2, 4, 1000));
    return true;
  }
};
aBless.share5 = function () {
  var content = "必得199金币";
  var UIText = utils.existsTextEndsWith(content);
  if (UIText) {
    aBless.share5Exec();
    return;
  }
  console.log("share5", "没找到-必得199金币-");
};
aBless.share5Exec = function () {
  var content = "必得199金币";
  for (var index = 0; index < 5; index++) {
    var UIText = utils.existsTextEndsWith(content);
    if (UIText) {
      utils.clickUIText(UIText);
      sleep(utils.getRandom(2, 3, 1000));
      utils.clickTextStartsWith("去粘贴");
      sleep(utils.getRandom(5, 7, 1000));
      back();
      sleep(utils.getRandom(5, 7, 1000));
      if (utils.existsText("继续分享")) {
        console.log("找到-继续分享-");
        utils.clickText("继续分享");
        sleep(utils.getRandom(2, 4, 1000));
      } else if (utils.existsText("开心收下")) {
        console.log("找到-开心收下-");
        utils.clickText("开心收下");
      }
    }
  }
};
aBless.goBack = function () {
  back();
  sleep(utils.getRandom(3, 4, 1000));
  var ocrItem = ocrGml.captureExistOne("放弃奖励");
  if (ocrItem) {
    back();
    sleep(utils.getRandom(2, 4, 1000));
  }
};
aBless.exec = function () {
  this.share5();
  sleep(utils.getRandom(1.5, 2, 1000));
  var UIText = utils.clickText("开福袋");
  if (UIText) {
    console.log("找到【开福袋】");
    sleep(utils.getRandom(1.5, 2, 1000));
    inTask.run(function () {
      var ocrItem = ocrGml.captureExistOne(["面对面", "邀好友"]);
      return ocrItem;
    });
    this.goBack();
    return;
  }
  console.log("没找到【开福袋】");
  this.goBack();
};

module.exports = aBless;
